#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

class CArray {
private:
    int size;
    int* ptr;
public:
    ~CArray()
    {
        if (ptr)
        {
            delete[] ptr;
            ptr = NULL;
        }
    }
    CArray(CArray& c)
    {
        ptr = new int[c.size];
        for (int i = 0; i < c.length(); i++)
        {
            ptr[size] = c[i];
            size++;
        }
    }
    CArray(int s=0)
    {
        size = s;
        if (s == 0)
            ptr = NULL;
        else
        ptr = new int[s];
    }
    void push_back(int x)
    {
        if (!ptr)
        {
            size = 0;
            ptr = new int[5];
        }
        ptr[size] = x;
        size++;
    }
    int length()
    {
        return size;
    }
    int& operator[](int i)
    {
        return ptr[i];
    }
};

int main()
{
    CArray a;
    for (int i = 0; i < 5; ++i)    a.push_back(i * i);
    for (int i = 0; i < 5; ++i) cout << a[i] << " ";
    cout << endl;

    CArray a2(3);
    a2[0] = 20; a2[1] = 21; a2[2] = 22;
    for (int i = 0; i < a2.length(); ++i) cout << a2[i] << " ";
    cout << endl;

    a2 = a;
    for (int i = 0; i < a2.length(); ++i) cout << a2[i] << " ";
    cout << endl;

    CArray a3;
    a2 = a3;
    cout << a2.length() << endl;

    a[3] = 100;
    CArray a4(a);
    for (int i = 0; i < a4.length(); ++i) cout << a4[i] << " ";
    return 0;
}